<template>
  <HomePanel title="新鲜好物" subTitle="新鲜出炉 品质靠谱">
    <!-- 下面是插槽主体内容模版 -->
    <template #main>
      <ul class="good-list">
        <li v-for="item in newsList" :key="item.id">
          <router-link :to="`/detail/${item.id}`">
            <img :src="item.picture" />
            <p class="name">{{ item.name }}</p>
            <p class="price">{{ item.price }}</p>
          </router-link>
        </li>
      </ul>
    </template>
  </HomePanel>
</template>

<script setup lang="ts">
//引入组件
import HomePanel from "./HomePanel.vue";
import { defineOptions, ref, onMounted } from "vue";
//引入接口
import { reqGetNewsList } from "@/apis/home";

defineOptions({
  name: "HomeNew",
});
let newsList = ref([]);
onMounted(() => {
  getNewsList();
});
const getNewsList = async () => {
  let res: any = await reqGetNewsList();
  // console.log(result);
  newsList.value = res.result;
};
</script>

<style scoped lang="scss">
.good-list {
  display: flex;
  height: 406px;
  background-color: #fff;
  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    margin: 5px;
    &:hover {
      transform: translate3d(0, -3px, 0);
      box-shadow: 0 3px 8px rgb(0 0 0 / 20%);
    }
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 20px;
      padding: 10px;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
      text-align: center;
    }
    .price {
      color: $priceColor;
    }
  }
}
</style>
